package com.gitee.zycra.future.job.common.vo;

import com.gitee.zycra.future.job.common.model.JobMetaData;
import com.gitee.zycra.jdbc.annotation.Column;
import com.gitee.zycra.jdbc.annotation.Table;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.time.LocalDateTime;

/**
 * @author zycra
 */
@Getter
@Setter
@ToString
@Accessors(chain = true)
@Table
public class JobMetaDataVO {

    /**
     * 主键
     */
    @Column("id")
    private Long id;

    /**
     * 应用名称
     */
    @Column("application_name")
    private String applicationName;

    /**
     * 任务类名
     */
    @Column("job_class_name")
    private String jobClassName;

    /**
     * 任务名称
     */
    @Column("job_name")
    private String jobName;

    /**
     * 失败重试次数
     */
    @Column("job_retry_times")
    private Integer jobRetryTimes;

    /**
     * 失败重试间隔(分钟)
     */
    @Column("job_retry_interval")
    private Integer jobRetryInterval;

    /**
     * 执行周期
     *
     * @see com.gitee.zycra.future.job.common.enums.JobCycleEnum
     */
    @Column("job_cycle")
    private Integer jobCycle;

    /**
     * 操作人姓名
     */
    @Column("operator_name")
    private String operatorName;

    /**
     * 更新时间
     */
    @Column("update_time")
    private LocalDateTime updateTime;

    /**
     * 是否有调度配置
     */
    private Boolean hasSchedule;

    public static JobMetaDataVO buildJobMetaDataVO(JobMetaData jobMetaData) {
        if (jobMetaData == null) {
            return null;
        }
        return new JobMetaDataVO()
                .setId(jobMetaData.getId())
                .setApplicationName(jobMetaData.getApplicationName())
                .setJobClassName(jobMetaData.getJobClassName())
                .setJobName(jobMetaData.getJobName())
                .setJobRetryTimes(jobMetaData.getJobRetryTimes())
                .setJobRetryInterval(jobMetaData.getJobRetryInterval())
                .setJobCycle(jobMetaData.getJobCycle())
                .setOperatorName(jobMetaData.getOperatorName())
                .setUpdateTime(jobMetaData.getUpdateTime());
    }
}
